﻿using System.IO;
using System.Net;
using System.Text;
using UnityEngine;

namespace PnFramework.Unity
{
    public class HttpWebKit
    {
        public static T GetWebJsonToObject<T>(string url)
        {
            var request = WebRequest.CreateHttp(url);
            request.Method = "GET";
            request.Accept = "application/json, text/javascript, */*; q=0.01";
            request.ContentType = "application/x-www-form-urlencoded; charset=UTF-8";
            using (var reader = new StreamReader(request.GetResponse().GetResponseStream(), Encoding.UTF8))
            {
                return JsonUtility.FromJson<T>(reader.ReadToEnd());
            }
        }
    }
}